package com.crazy.common;
import java.security.MessageDigest;
import java.util.UUID;
/**
 * 工具类
 * @author Zhang Weiwei
 * @since 2013-9-21上午10:44:26
 */
public class Tools {
	static final char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7',
			'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
	/**
	 * 获取全球唯一标识符
	 * @author Zhang Weiwei
	 * @since 2013-8-31下午2:00:33
	 * @return
	 */
	public static String getUUID() {
		return UUID.randomUUID().toString().replace("-", "");
	}
	/**
	 * 使用md5对输入内容进行加密
	 * @author Zhang Weiwei
	 * @since 2013-9-25下午11:20:46
	 * @param input 输入内容
	 * @return
	 */
	public static String md5Crypt(String input) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(input.getBytes());
			byte[] bytes = md.digest();
			int j = bytes.length;
			char[] chars = new char[j * 2];
			int k = 0;
			for (int i = 0; i < j; i++) {
				byte b = bytes[i];
				chars[k++] = hexDigits[b >>> 4 & 0xf];
				chars[k++] = hexDigits[b & 0xf];
			}
			return new String(chars);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}
